package com.hai.boot.config;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.hai.boot.interceptors.UserInterceptors;

import jakarta.servlet.Filter;
@Configuration
public class WebConfig implements WebMvcConfigurer{
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("signup");
		WebMvcConfigurer.super.addViewControllers(registry);
	}
	@Bean
	public FilterRegistrationBean filterRegistrationBean() {
		FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
		characterEncodingFilter.setEncoding("UTF-8");
		characterEncodingFilter.setForceEncoding(true);
		filterRegistrationBean.setFilter(characterEncodingFilter);
		filterRegistrationBean.addUrlPatterns("/**");
		filterRegistrationBean.addUrlPatterns("/back/**");
		return filterRegistrationBean;
		
	}
	@Autowired
	UserInterceptors userInterceptors;
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		registry.addInterceptor(userInterceptors).addPathPatterns("/back");
		registry.addInterceptor(userInterceptors).addPathPatterns("/map");
		registry.addInterceptor(userInterceptors).addPathPatterns("/form");
		registry.addInterceptor(userInterceptors).addPathPatterns("/table");
		registry.addInterceptor(userInterceptors).addPathPatterns("/_table");
		WebMvcConfigurer.super.addInterceptors(registry);
	}
	
}
